<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
    <button id="btn">登录</button>

    <script>
        // 抽离公共方法
        var getSingle = (() => {
            var result;
            return function (fn) {
                return result || (result = fn.apply(this,arguments))
            }
        })()

        var createDiv = function () {
            var div = document.createElement("div")
            div.innerHTML = "登录弹窗"
            div.style.display = "none"
            document.body.appendChild(div)
            return div
        }

        var createIframe = function () {
            var iframe = document.createElement("iframe")
            iframe.src = "https://www.baidu.com"
            iframe.style.width = "500px"
            iframe.style.height = "500px"
            iframe.style.display = "none"
            document.body.appendChild(iframe)

            return iframe
        }

        // document.getElementById("btn").onclick = function () {
        //     var div = getSingle(createDiv)
        //     div.style.display = "block"
        // }

        document.getElementById("btn").onclick = function () {
            var iframe = getSingle(createIframe)
            iframe.style.display = "block"
        }

    </script>
</body>
</html>